package com.wuwei.business.controller;

import com.wuwei.business.Dto.CarDto;
import com.wuwei.business.domain.BusCar;
import com.wuwei.business.service.IBusCarService;
import com.wuwei.common.core.controller.BaseController;
import com.wuwei.common.core.domain.AjaxResult;
import com.wuwei.common.core.domain.model.LoginUser;
import com.wuwei.common.core.page.TableDataInfo;
import com.wuwei.common.enums.BusinessType;
import com.wuwei.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.List;

/**
 * 内容: SSM
 * 作者: weishao
 */
@RestController
@Api(tags = "车辆管理接口")
@RequestMapping("business/car")
public class BusCarController extends BaseController {

    @Autowired
    private IBusCarService busCarService;
    /**
     * 查询车辆列表
     */
    @GetMapping("/list")
    @ApiOperation("车辆查询")
    public TableDataInfo list(CarDto carDto)
    {
        startPage();
//        String username = SecurityUtils.getUsername();
//        上面这个是个类取值
//       下面是方法可以带进去取
        LoginUser loginUser = getLoginUser();
        List<BusCar> list = busCarService.getCarPage(loginUser,carDto);
        return getDataTable(list);
    }

    /**
     * 新增车辆
     */
    @PostMapping
    @ApiOperation("添加车辆")
    public AjaxResult addCar(@RequestBody CarDto carDto) {
        LoginUser loginUser = getLoginUser();
        return toAjax(busCarService.addCar(carDto,loginUser));
    }
    /**
     * 显示车辆
     */
    @GetMapping("{id}")
    @ApiOperation("根据id查询车辆")
    public AjaxResult getCarInfo(@PathVariable("id") Long id) {
        CarDto carDto = busCarService.getCarInfo(id);
        return AjaxResult.success(carDto);
    }
    /**
     * 车辆修改
     */
    @PutMapping
    @ApiOperation("车辆修改")
    public AjaxResult updateCar(@RequestBody CarDto carDto) {
        LoginUser loginUser = getLoginUser();
        return toAjax(busCarService.updateCar(carDto, loginUser));
    }
    /**
     * 批量删除车辆
     */
    @DeleteMapping("{ids}")
    @ApiOperation("车辆删除根据id")
    public AjaxResult delCar(@PathVariable("ids") List<Long> ids) {
        LoginUser loginUser = getLoginUser();
        return toAjax(busCarService.delCar(ids, loginUser));
    }

}
